'use strict';

var mongoose = require('mongoose'),
    Schema = mongoose.Schema;

var TimelineSchema = new Schema({
  _user: {
    type: Schema.Types.ObjectId,
    ref: 'User'
  },
  type: {
    type: String,
    required: true
  },
  message: {
    type: String,
    required: true
  },
  created_at: {type: Date, default: Date.now},
  updated_at: {type: Date, default: Date.now}
});
TimelineSchema
  .pre('save', function(next) {
    if (!this.isNew) this.updated_at = Date.now;
    next();
  });

module.exports = mongoose.model('Timeline', TimelineSchema);
